import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_widgets/widgets/button/kq_small_button.dart';

enum MarginPosition {
  /// 右边的margin
  right,

  /// 左边的margin
  left
}

class KqFormCustomView extends StatefulWidget {
  /// 默认：8.r
  final double? marginHor;

  /// 间距的位置
  final MarginPosition? position;

  /// customView为空时，渲染KqSmallButton，title为按钮文本
  final String? title;

  /// KqSmallButton回调
  final Function(bool disabled)? onTap;

  final Widget? customView;
  const KqFormCustomView({
    Key? key,
    this.marginHor,
    this.position = MarginPosition.left,
    this.title,
    this.onTap,
    this.customView,
  }) : super(key: key);

  @override
  State<KqFormCustomView> createState() => _KqFormCustomViewState();
}

class _KqFormCustomViewState extends State<KqFormCustomView> {
  @override
  Widget build(BuildContext context) {
    if (widget.position == MarginPosition.left) {
      return Row(
        children: [
          SizedBox(
            height: 1,
            width: widget.marginHor ?? 8.r,
          ),
          widget.customView ??
              KqSmallButton(
                title: widget.title ?? '',
                onTap: (disabled) {
                  widget.onTap?.call(disabled);
                },
              )
        ],
      );
    }
    return Row(
      children: [
        widget.customView ??
            KqSmallButton(
              title: widget.title ?? '',
              onTap: (disabled) {
                widget.onTap?.call(disabled);
              },
            ),
        SizedBox(
          height: 1,
          width: widget.marginHor ?? 8.r,
        ),
      ],
    );
  }
}
